/**
 * 冒泡排序
 * @param arr
 * @returns {*}
 */


function bubbleSort(arr) {
    for(let i = 0; i< arr.length -1; i++) {
        for(let j = 0; j< arr.length -i -1 ; j ++){
            if(arr[j] > arr[j +1]){
                let temp;
                temp = arr[j]
                arr[j] = arr[j +1]
                arr[j +1 ] = temp
            }
        }
    }
    return arr;
}

const arr = [1, 8, 9, 10, 1, 2, 3, 4]
console.log(bubbleSort(arr));

function quickSort(arr) {

    const len = arr.length
    if (len <= 0) return arr
    const provitIndex = Math.floor(len/2)
    const provit = arr.splice(provitIndex, 1)[0]

    const left = []
    const right = []

    for (let i =0; i<len; i++) {
        if(arr[i]<=provit){
            left.push(arr[i])
        }else {
            right.push(arr[i])
        }
    }
    return [...quickSort(left), provit, ...quickSort(right)]
}

console.log(quickSort(arr));
